<?php

require_once($INCLUDE_PATH.'app/controller/InitController.php');
require_once ($INCLUDE_PATH . "/inc/checkfun.php");
require_once ($INCLUDE_PATH . "/include/checklogin.php");
require_once ($INCLUDE_PATH . "/include/WebService2Db.php");
function __autoload($class_name) {
    require_once APP_ROOT.'app/model/'.strtolower($class_name) . '.php';
}
class PostController extends InitController {

    public function __construct() {
        parent::__construct();

    }
    //用户验证
    public  function actionTem() {
        $key = $_REQUEST['key'];
        $keyselect = PostModel::checkkey($key);
        if ($keyselect) {
            $pid = $_REQUEST['pid'];
            $res = PostModel::selecttem($pid);
            if($res) {

                $l = "[";
                $j = 1;
                foreach ($res as  $list) {
                    $i=0;
               if($j == 1 ){
                    $l .= "{";
                }else
                {
                    $l .= ",{";
                }
                    foreach ($list as $key=>$u) {
                        if(($i%2)!=0){
                        $l .= ','.$key.':"'.$u.'"';
                        }
                        $i++;
                    }
               
                    $l .= "}";
               
                $j++;
                }
                $l .= "]";
                $l = str_replace("{,","{",$l);
                echo $l;
            }
        }
        Y::$htmlFile = 'index/empty.html';
    }
    public  function actionUrl() {
        $key = $_REQUEST['key'];
        $keyselect = PostModel::checkkey($key);
        if ($keyselect) {
            $res = PostModel::selecturl();
            if($res) {
                 $j = 1;
                $l = "[";
                foreach ($res as  $list) {
                    $i=0;
                    if($j == 1 ){
                    $l .= "{";
                }else
                {
                    $l .= ",{";
                }
                    foreach ($list as $key=>$u) {
                        if ($key === 'url'){
                        $l .= $key.':"'.$u.'"';
                        }else{

                        }
                    }
                 
                    $l .= "}";
                
                $j++;
                }
                $l .= "]";
                echo $l;
            }
        }
        Y::$htmlFile = 'index/empty.html';

    }
    public  function actionEmail() {
        $sum = $_REQUEST['sum'];
        $key = $_REQUEST['key'];
        $sendtype =$_REQUEST['sendtype'];
        $keyselect = PostModel::checkkey($key);
        
        if ($keyselect) {
            $pid = $_REQUEST['pid'];
            $res = PostModel::selectemail($pid,$sum,$sendtype);
    
            if($res) {
                $j=1;
                $l = "[";
                foreach ($res as  $list) {
                    if($j == 1 ){
                    $l .= "{";
                }else
                {
                    $l .= ",{";
                }
    
                    foreach ($list as $key=>$u) {
                        if($key === "id" or $key === "pid" or $key==="email"){
                        $l .= ','.$key.':"'.$u.'"';
                        }
                        $i++;
                    }
                        $j++;
                    $l .= "}";
                }
                $l .= "]";
                 $l = str_replace("{,","{",$l);
                echo $l;

            }
        }
        Y::$htmlFile = 'index/empty.html';
    }
    //获取可执行营销项目
    public function actionItem() {
        $key = $_REQUEST['key'];
        $keyselect = PostModel::checkkey($key);
        if ($keyselect) {
            $res = PostModel::selectitem();
            if($res) {
                $l = "[";
                $j=1;
                foreach ($res as  $list) {
                    if($j == 1 ){
                    $l .= "{";
                }else
                {
                    $l .= ",{";
                }
                    $i = 0;
                    foreach ($list as $key=>$u) {
                        if(($i%2) != 0){
                        if ($key === 0)
                        {
                              $l .= ','.$key.':"'.$u.'"';
                        }
                        else{
                        
                        $l .= ','.$key.':"'.$u.'"';
                        }
                        }
                        $i++;
                    }
                    $l .= "}";
                    $j++;
                }
                $l .= "]";
                $l = str_replace("{,","{",$l);
                echo $l;
            }
        }
        Y::$htmlFile = 'index/empty.html';

    //echo PRE.'hhj';
    }




}

?>
